/*
 * WOWCamera.cpp
 *
 *  Created on: 08.10.2012
 *      Author: caffeine
 */

#include "WOWCamera.h"


#include <log/Log.h>

WOWCamera::WOWCamera(irr::scene::ISceneManager*manager,irr::scene::ISceneNode*parent):irr::scene::ISceneNode(parent,manager){
	camera=manager->addCameraSceneNode(this,irr::core::vector3df(0,0,0));
	anim=new irr::scene::TPCAnim(manager,this,camera);
	camera->addAnimator(anim);
	camera->setInputReceiverEnabled(true);
	manager->setActiveCamera(camera);
	entity=0;
	height=0;
	box=irr::core::aabbox3df(-1,-1,-1,1,1,1);
	if (parent)
		parent->addChild(this);
	else
		manager->getRootSceneNode()->addChild(this);
}

WOWCamera::~WOWCamera() {
	setEntity(0);
	camera->remove();
	anim->drop();
}

irr::scene::TPCAnim*WOWCamera::getTPCAnimatior(){
	return anim;
}

void WOWCamera::setEntity(irr::scene::ISceneNode*e){
	if (entity)
		entity->drop();
	entity=e;
	if (entity)
		entity->grab();
}

irr::scene::ICameraSceneNode*WOWCamera::getCamera(){
	return camera;
}

void WOWCamera::updatePositionOfEntity(){
	if (height==0)
		setPosition(entity->getPosition());
	else
		setPosition(irr::core::vector3df(entity->getPosition().X,entity->getPosition().Y+height,entity->getPosition().Z));
}

void WOWCamera::setHeight(irr::f32 h){
	height=h;
}

irr::f32 WOWCamera::getHeight(){
	return height;
}

void WOWCamera::OnRegisterSceneNode(){
	//SceneManager->registerNodeForRendering(this);
	//updatePositionOfEntity();
	updatePositionOfEntity();
}
void WOWCamera::render(){

}
const irr::core::aabbox3df& WOWCamera::getBoundingBox() const{
	return box;
}
irr::u32 WOWCamera::getMaterialCount() const{
	return 0;
}
irr::video::SMaterial& WOWCamera::getMaterial(irr::u32 i){
	return camera->getMaterial(i);
}
